package ua.kpi.oblamskyiv.testcase.question;

import ua.kpi.oblamskyiv.counter.AnswersScoreCounter;
import ua.kpi.oblamskyiv.io.exception.IllegalAnswerFormatException;
import ua.kpi.oblamskyiv.parser.AnswersParser;
import ua.kpi.oblamskyiv.testcase.Answers;

public abstract class AbstractQuestion implements Question {
    private AnswersScoreCounter counter;
    private AnswersParser parser;
    private String value;
    private Answers correctAnswers;

    public AbstractQuestion(String value,
                            Answers correctAnswers,
                            AnswersScoreCounter counter,
                            AnswersParser parser) {
        this.value = value;
        this.correctAnswers = correctAnswers;
        this.counter = counter;
        this.parser = parser;
    }

    @Override
    public double getAnswersScore(Answers userAnswers) {
        return counter.countScore(this, userAnswers);
    }

    @Override
    public Answers getAnswersFromString(String userAnswers)
            throws IllegalAnswerFormatException {
        return parser.parse(this, userAnswers);
    }

    @Override
    public Answers getCorrectAnswers() {
        return correctAnswers;
    }

    @Override
    public String toString() {
        return value + "\n";
    }
}
